<template>
	<div>
		<el-tree :data="menuData" :props="defaultProps"  node-key="id" ref="treeComponent" :show-checkbox="checked"></el-tree>
		<div style="text-align: right;margin-top: 10px;">
			<el-button type="primary" size="small" @click="onOk">确定</el-button>
		</div>
	</div>
</template>

<script>
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: "RelRoleMenuPage",
		props: ["currentId"],
		data() {
			return {
				value: [],
				menuData: [],
				defaultProps: {
					children: 'children',
					label: 'name'
				},
				checked: true,
			}
		},mounted() {
			//this.init();
		},methods: {
			init(){
				var that = this;
				restUtil.getAction(this,"relrolemenupage/init?resRoleId="+this.currentId).then(
					function(response) {
						if (response.data.code == 1) {
							that.menuData = [response.data.menuData];
							that.$refs.treeComponent.setCheckedKeys(response.data.valueList, true);
						} else {
							that.$alert(response.data.message, '提示')
						}
					});
			},
			onOk() {
				var checkedKeys = this.$refs.treeComponent.getCheckedKeys();
				var value=[];
				for(var i=0;i<checkedKeys.length;i++){
					value.push(parseInt(checkedKeys[i]));
				}
				var that = this;
				var request={
					"valueList":value,
					"resRoleId":this.currentId
				};
				restUtil.postAction(this,"relrolemenupage/dataSave",request).then(
					function(response) {
						if (response.data.code == 1) {
							that.$emit("closeDialogEvent",this);
						} else {
							that.$alert(response.data.message, '提示')
						}
					});
			}
		},
	}
</script>


<style>
</style>
